/**
 * 
 */
package com.thinkgsp.jxc.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.thinkgsp.jxc.model.InventoryAdd;
import com.thinkgsp.jxc.persistence.InventoryAddMapper;
import com.thinkgsp.jxc.service.InventoryAddService;
import com.thinkgsp.jxc.service.ServiceException;

/**
 * 存货地址业务实现类
 * @author evan
 *
 */
@Service("invAddService")
@Transactional
public class InventoryAddServiceImpl extends GeneralServiceImpl implements
		InventoryAddService {

	@Autowired
	private InventoryAddMapper invAddMapper;
	/* (non-Javadoc)
	 * @see com.thinkgsp.jxc.service.InventoryAddService#setInventoryAddMapper(com.thinkgsp.jxc.persistence.InventoryAddMapper)
	 */
	public void setInventoryAddMapper(InventoryAddMapper invAddMapper) {
		this.invAddMapper = invAddMapper;
	}

	/* (non-Javadoc)
	 * @see com.thinkgsp.jxc.service.InventoryAddService#getInventoryAdd(java.lang.Integer)
	 */
	public InventoryAdd getInventoryAdd(Integer invId) {
		return invAddMapper.getInventoryAdd(invId);
	}

	/* (non-Javadoc)
	 * @see com.thinkgsp.jxc.service.InventoryAddService#getAllInventoryAdd()
	 */
	public List<InventoryAdd> getAllInventoryAdd() {
		return invAddMapper.getAllInventoryAdd();
	}

	/* (non-Javadoc)
	 * @see com.thinkgsp.jxc.service.InventoryAddService#getInventoryAddByDept(java.lang.Integer)
	 */
	public List<InventoryAdd> getInventoryAddByDept(Integer deptId) {
		return invAddMapper.getInventoryAddByDept(deptId);
	}

	/* (non-Javadoc)
	 * @see com.thinkgsp.jxc.service.InventoryAddService#insertInventoryAdd(com.thinkgsp.jxc.model.InventoryAdd)
	 */
	public void saveInventoryAdd(InventoryAdd invAdd) {
		if(invAdd.getId() == null || invAdd.getId() == 0) {
			invAddMapper.insertInventoryAdd(invAdd);
		} else {
			invAddMapper.updateInventoryAdd(invAdd);
		}
	}

	/* (non-Javadoc)
	 * @see com.thinkgsp.jxc.service.InventoryAddService#deleteInventoryAdd(java.lang.Integer)
	 */
	public void deleteInventoryAdd(Integer invAddId) throws ServiceException {
		int cnt = invAddMapper.getInventoryCount(invAddId);
		if(cnt == 0) {
			invAddMapper.deleteInventoryAdd(invAddId);
		} else {
			throw new ServiceException("存货地址中存在库存,不允许删除！");
		}
	}

}
